<template>
  <div>
    <el-container>
      <el-aside :style="{ width: isCollapse ? 'auto' : '200px' }">
        <navbar :menus="menus" :collapse="isCollapse"></navbar>
      </el-aside>

      <el-container>
        <el-header>
          <i
            class="el-collapse el-icon-s-fold"
            :class="isCollapse ? 'collapseTransform' : ''"
            @click="handleCollapse"
          ></i>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
        <el-footer> Copyright © 2021 没啥用科技 All Rights Reserved </el-footer>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import routes from "../router/routes";
import Navbar from "../components/Navbar";
export default {
  components: {
    Navbar,
  },
  data() {
    return {
      isCollapse: false,
    };
  },
  methods: {
    handleCollapse() {
      this.isCollapse = !this.isCollapse;
      console.log(this.isCollapse);
    },
    resolve(arr, parentPath = "") {
      let newArr = [];

      arr.forEach((route) => {
        let obj = Object.assign({}, route);

        parentPath =
          parentPath && parentPath.lastIndexOf("/") !== parentPath.length - 1
            ? parentPath + "/"
            : parentPath;

        obj.path = parentPath + obj.path;
        console.log(obj.path);
        if (obj.children && obj.children.length > 0) {
          obj.children = this.resolve(obj.children, obj.path);
        }
        newArr.push(obj);
      });
      console.log(newArr);
      return newArr;
    },
  },
  computed: {
    menus() {
      let arr = this.resolve(routes);

      return arr;
    },
  },
};
</script>

<style scoped>
.el-aside {
  width: 200px;
}
.el-header {
  background-color:rgb(198, 238, 238);
}
.el-main {
  background-color: azure;
}
.el-footer {
  background-color: rgb(198, 238, 238);
  display: flex;
  align-items: center;
  justify-content: center;
}
.el-collapse {
  font-size: 2rem;
  margin-top: 0.7rem;
}
.collapseTransform {  
  transform: rotate(-180deg);
}
</style>